#include<map>
#include<iostream>
using namespace std;
int main(){
	map<string,map<string,int> >a;
	int n,c;
	string g,f;
	cin>>n;
	while(n--){
		cin>>f>>g>>c;
		a[g][f]+=c;
	}
	for(map<string,map<string,int> >::iterator it=a.begin();it!=a.end();++it){
		cout<<it->first<<endl;
		for(map<string,int>::iterator ot=it->second.begin();ot!=it->second.end();++ot)
			cout<<"   |----"<<ot->first<<'('<<ot->second<<')'<<endl;
	}
	return 0;
}